n, k = map(int, input().split())
nums = list(map(int, input().split()))
sums = sum(nums)
left = 0
right = sums


def f(num):  # 最大时间为num是否可行
    cnt = 1
    i = 0
    accumulates = 0
    while i < n:
        if nums[i] > num: return False
        accumulates += nums[i]
        if accumulates > num:
            cnt += 1
            accumulates = nums[i]
        i += 1
    return cnt <= k


answer = right
while left <= right:
    mid = (left + right) >> 1
    if f(mid):
        answer = mid
        right = mid - 1
    else:
        left = mid + 1
print(answer)
